﻿#include<iostream>
#include<string>
#include<curl.h>
using namespace std;
size_t writeCallback(void* contents, size_t size, size_t nmemb, std::string* output) {
    size_t totalSize = size * nmemb;
    output->append((char*)contents, totalSize);
    return totalSize;
}
int main() {
    CURL* curl;
    CURLcode statusCode;
    string htmlData;

    curl_global_init(CURL_GLOBAL_DEFAULT);
    curl = curl_easy_init();
    if (curl) {
        // 设置要抓取的网页地址
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_easy_setopt(curl, CURLOPT_URL, "https://ssr1.scrape.center");
        // 设置回调函数，用于处理获取到的响应数据
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &htmlData);
        // 执行 HTTP 请求
        auto res = curl_easy_perform(curl);
        if (res != CURLE_OK) {
            std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
        }

        // 输出获取到的网页内容
        //std::cout << htmlData << std::endl;
        /*fstream out("html.txt");
        out << htmlData;
        out.close();*/
        /*for (int i = 0; i < vt.size(); ++i) {
            cout << vt[i] << endl;
        }*/

        // 清理 CURL 实例
        curl_easy_cleanup(curl);
    }
    else {
        std::cerr << "curl_easy_init() failed." << std::endl;
    }
}